package com.bnlr.lrparking.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.MyPublishBean;
import com.bnlr.lrparking.util.CommonUtil;

import java.util.List;

/**
 * 我的发布adapter
 * @author tian
 */


public class MyPublishAdapter extends BaseMultiItemQuickAdapter<MyPublishBean.DataBean,BaseViewHolder>{
    private OnItemDeleteListener onItemDeleteListener;
    private OnItemOffListener monItemOffListener;
    public MyPublishAdapter(List<MyPublishBean.DataBean> data) {
        super(data);
        addItemType(MyPublishBean.DataBean.CHU_ZU, R.layout.item_my_publish_layout);
        addItemType(MyPublishBean.DataBean.CHU_SHOU, R.layout.item_my_publish_layout);
        addItemType(MyPublishBean.DataBean.QIU_ZU, R.layout.item_my_publish_beg_layout);
        addItemType(MyPublishBean.DataBean.QIU_GOU, R.layout.item_my_publish_beg_layout);
    }

    public void setOnItemDeleteListener(OnItemDeleteListener onItemDeleteListener) {
        this.onItemDeleteListener = onItemDeleteListener;
    }



    public void setOnItemOffListener(OnItemOffListener onItemOffListener) {
        this.monItemOffListener = onItemOffListener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MyPublishBean.DataBean item) {
        switch (helper.getItemViewType()) {
            case MyPublishBean.DataBean.CHU_ZU:
            case MyPublishBean.DataBean.CHU_SHOU:
                SwipeMenuLayout car_swipe=helper.getView(R.id.publish_swipe_menu);
                RelativeLayout rl_publish = helper.getView(R.id.rl_publish);
                helper.setText(R.id.item_my_publish_date,"发布于 "+CommonUtil.timeGap(item.getCreateTime()));
                helper.setText(R.id.item_my_publish_type,item.getStatus());
                helper.setText(R.id.item_my_publish_title,item.getTitle());
                Glide.with(mContext).load(item.getPhotoUrl()).
                        placeholder(R.mipmap.tab2_defaultgraph).error(R.mipmap.tab2_defaultgraph).into((ImageView) helper.getView(R.id.item_my_publish_iv));
                TextView tvAudit = helper.getView(R.id.tv_publish_audit);
                Button btnDel=helper.getView(R.id.item_my_publish_delete);
                Button btnOff=helper.getView(R.id.item_my_publish_off);
                TextView tvCause = helper.getView(R.id.audit_cause);
                switch (item.getAuditStatus()) {
                    // 审核状态 0正常，1下线，2待审核，3审核不通过，4用户删除
                    case 0:
                        helper.setText(R.id.item_my_publish_status,"显示中");
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        tvAudit.setText("审核成功");
                        car_swipe.setSwipeEnable(true);
                        btnOff.setVisibility(View.VISIBLE);
                        tvCause.setVisibility(View.GONE);
                        tvAudit.setBackgroundColor(Color.parseColor("#00CAA3"));
                        break;
                    case 1:
                        car_swipe.setSwipeEnable(true);
                        helper.setText(R.id.item_my_publish_status,"已下线");
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        btnOff.setText("上线");
                        tvAudit.setText("审核成功");
                        tvAudit.setBackgroundColor(Color.parseColor("#00CAA3"));
                        btnOff.setVisibility(View.VISIBLE);
                        tvCause.setVisibility(View.GONE);
                        break;
                    case 2:
                        tvAudit.setText("正在审核");
                        tvAudit.setBackgroundColor(Color.parseColor("#00CAA3"));
                        helper.setText(R.id.item_my_publish_status,"正在审核");
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        car_swipe.setSwipeEnable(false);
                        tvCause.setVisibility(View.GONE);
                        break;
                    case 3:
                        car_swipe.setSwipeEnable(true);
                        tvAudit.setText("审核失败");
                        tvCause.setVisibility(View.VISIBLE);
                        btnOff.setVisibility(View.GONE);
                        helper.setTextColor(R.id.item_my_publish_status,Color.parseColor("#ea5544"));
                        helper.setText(R.id.item_my_publish_status,"审核失败");
                        tvAudit.setBackgroundColor(Color.parseColor("#ea5544"));
                        break;
                    case 4:
                        car_swipe.setSwipeEnable(false);
                        break;
                    default:
                        break;
                }
                btnDel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemDeleteListener.onDelete(v,helper.getAdapterPosition(),item);
                    }
                });
                helper.addOnClickListener(R.id.audit_cause);

                /*tvCause.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemSeeCauseListener.onSeeCause(v,helper.getAdapterPosition(),item);
                    }
                });*/
                btnOff.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        monItemOffListener.onOff(v,helper.getAdapterPosition(),item);
                    }
                });

                break;
            case MyPublishBean.DataBean.QIU_ZU:
            case MyPublishBean.DataBean.QIU_GOU:
                SwipeMenuLayout car_swipe1=helper.getView(R.id.publish_swipe_menu);
                RelativeLayout rl_publish_beg = helper.getView(R.id.rl_publish_beg);
                helper.setText(R.id.item_my_publish_date,"发布于 "+CommonUtil.timeGap(item.getCreateTime()));
                helper.setText(R.id.item_my_publish_beg_type,item.getStatus());
                helper.setText(R.id.item_my_publish_beg_title,item.getTitle());
                Button car_btnDel=helper.getView(R.id.item_my_publish_beg_delete);
                Button car_btnOff=helper.getView(R.id.item_my_publish_beg_off);
                TextView tvCause1 = helper.getView(R.id.audit_beg_cause);
                switch (item.getAuditStatus()) {
                    // 审核状态 0正常，1下线，2待审核，3审核不通过，4用户删除
                    case 0:
                        helper.setText(R.id.item_my_publish_status,"显示中");
                        car_swipe1.setSwipeEnable(true);
                        car_btnOff.setText("下线");
                        car_btnOff.setVisibility(View.VISIBLE);
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        tvCause1.setVisibility(View.GONE);
                        break;
                    case 1:
                        car_swipe1.setSwipeEnable(true);
                        helper.setText(R.id.item_my_publish_status,"已下线");
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        car_btnOff.setText("上线");
                        car_btnOff.setVisibility(View.VISIBLE);
                        tvCause1.setVisibility(View.GONE);
                        break;
                    case 2:
                        helper.setText(R.id.item_my_publish_status,"正在审核");
                        helper.setTextColor(R.id.item_my_publish_status,mContext.getResources().getColor(R.color.main_color));
                        car_swipe1.setSwipeEnable(false);
                        tvCause1.setVisibility(View.GONE);
                        break;
                    case 3:
                        car_swipe1.setSwipeEnable(true);
                        helper.setTextColor(R.id.item_my_publish_status,Color.parseColor("#ea5544"));
                        helper.setText(R.id.item_my_publish_status,"审核失败");
                        car_btnOff.setVisibility(View.GONE);
                        tvCause1.setVisibility(View.VISIBLE);
                        break;
                    case 4:
                        car_swipe1.setSwipeEnable(false);
                        break;
                    default:
                        break;
                }
                car_btnDel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemDeleteListener.onDelete(v,helper.getAdapterPosition(),item);
                    }
                });
                helper.addOnClickListener(R.id.audit_beg_cause);
                car_btnOff.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        monItemOffListener.onOff(v,helper.getAdapterPosition(),item);
                    }
                });


                break;
            default:
                break;

        }

    }
    //删除
    public interface OnItemDeleteListener {
        void onDelete(View view,int position,MyPublishBean.DataBean item);
    }

    //下线上线
    public interface OnItemOffListener {
        void onOff(View view,int position,MyPublishBean.DataBean item);
    }
}
